/*
 * DatabaseConnectionInformer.cpp
 *
 *  Created on: 20 ��� 2010
 *      Author: Sartios
 */

#include "DatabaseConnectionInformer.h"

#include "../../Validators/NameValidators/DbNameValidator/DbNameValidator.h"
#include "../../Validators/NameValidators/DbUsernameValidators/DbUsernameValidators.h"
#include "../../Validators/CodeValidators/PasswordDbValidators/PasswordDbValidator.h"

#include "../../Exceptions/DbPasswordExceptions/InvalidPasswordStructure.h"

DatabaseConnectionInformer::DatabaseConnectionInformer() {
	dbName_=0;
	password_=0;
	username_=0;

}

DatabaseConnectionInformer::~DatabaseConnectionInformer() {
	delete dbName_;
	delete password_;
	delete username_;
}

DatabaseConnectionInformer::DatabaseConnectionInformer(const string *dbName,const string *username,const string *password){
	setDbName(dbName);
	setUsername(username);
	setPassword(password);
}

bool	DatabaseConnectionInformer::setDbName(const string *dbName){
	if(0!=dbName){
		DbNameValidator dbNameValidator;

		if(dbNameValidator.dbNameIsCorrect(dbName)){
			dbName_=new string(dbName->c_str());
			return true;
		}
	}
}

string	*	DatabaseConnectionInformer::getDbName()const{
	if(0!=dbName_){
		return dbName_;
	}
}

bool	DatabaseConnectionInformer::setUsername(const string *username){
	if(0!=username){

		DbUsernameValidators usernameValidator;

		if(usernameValidator.usernameIsCorrect(username)){
			username_=new string(username->c_str());
			return true;
		}
		throw InvalidPasswordStructure("Wrong username structure");
	}
}

string	*	DatabaseConnectionInformer::getUsername()const{
	if(0!=username_){
		return username_;
	}
}

bool	DatabaseConnectionInformer::setPassword(const string *password){
	if(0!=password){
		PasswordDbValidator passwordValidator;

		if(passwordValidator.passwordIsCorrect(password)){
			password_=new string(password->c_str());
			return true;
		}
		throw InvalidPasswordStructure("Wrong password structure");
	}
}

string	*	DatabaseConnectionInformer::getPassword()const{
	if(0!=password_){
		return password_;
	}
}
